// ------------------------------------------------------------------- 纯 APP 调用方法
function appLocation(json) {
  console.log(json);
  var u = navigator.userAgent;
  var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; // android终端
  var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
  /*
   * iOS:用window.location = json 传值; Andorid用：window.control.droidAct(json);
   */
  if (isAndroid) {
    window.control.droidAct(json);
  } else if (isiOS) {
    window.location = json;
  }

}
// web 打开商品详情
function openH5Serv(id) {
  window.location.href = 'http://carnt.carnettong.com:8088/CARNT/jsp/pay/indexM.html#/shopDetail/' + id;
}

function openH5SeckServ(seckillDetailId, startDate, endDate) {
  window.location.href = "http://carnt.carnettong.com:8088/CARNT/jsp/pro/prodetail.jsp?servId=" + seckillDetailId;
}

// 打开秒杀
function openSeckill(sid) {
  var json = "json:" + JSON.stringify({
    action: "seckill",
    compId: "",
    firstClass: "",
    id: sid
  });
  appLocation(json);
}

// 打开我的4S店
function openShop4S(sCompId, sFirstClass) {
  var json = "json:" + JSON.stringify({
    action: "shop4s",
    compId: sCompId,
    firstClass: sFirstClass,
    id: ""
  });
  appLocation(json);
}

// 打开服务或商品
function openServ(sId) {
  var json = "json:" + JSON.stringify({
    action: "servDetail",
    compId: "",
    firstClass: "",
    id: sId
  });
  appLocation(json);
}

function getQuantity(quantity) {
  var json = "json:" + JSON.stringify({
    action: "getQuantity",
    quantity: quantity
  });
  appLocation(json);
}

function seemorecomment() {
  var json = "json:" + JSON.stringify({
    action: "comment"
  });
  appLocation(json);
}

function addtoshoppingcart(sid, sCompId) {
  var json = "json:" + JSON.stringify({
    action: "shoppingcart",
    id: sid,
    compId: sCompId
  });
  appLocation(json);
}
//分享参数
function share(title, desc, link, imgUrl) {
  var json = "json:" + JSON.stringify({
    action: "share",
    title: title,
    desc: desc,
    link: link,
    imgUrl: imgUrl
  });
  appLocation(json);
}

//打开4sCafe介绍页
function open4sCafeDesc(sCompId) {
  var json = "json:" + JSON.stringify({
    action: "4scafeDesc",
    compId: "http://112.124.107.78:8088/CARNT/desc/" + sCompId + ".html"
  });
  appLocation(json);
}
//App去登录页面(原地刷新)
function logIn(){
  var json="json:"+JSON.stringify({
    action:"login"
  });
  appLocation(json);
}
//App去登录页面(去首页)
function signIn(){
  var json="json:"+JSON.stringify({
    action:"signIn",
    desc: '请先登录'
  });
  appLocation(json);
}
// 统一板块跳转
function sendAppRedirect(action){
  var json = "json:" + JSON.stringify({
    action:action,
    compId:"",
    firstClass:"",
    id:""
  });
  appLocation(json);
}

// 打开4S咖啡
function fourSCafe(){
  var json = "json:" + JSON.stringify({
    action:'4scafe'
  });
  appLocation(json);
}

// 跳转车品 action 为 carShop
function carShop(){
  var json = "json:" + JSON.stringify({
    action:'carShop'
  });
  appLocation(json);
}
// ------------------------------------------------------------------- H5 & APP 公用方法 （需有window._Global_）

// 打开商品详情页面
function H5AppOpen (goodsId) {
  if ( _Global_ == 'web' ) {
    // H5
    openH5Serv(goodsId);
  } else {
    // App
    openServ('S_' + goodsId);
  }
}
// 打开智能保养
function openMaintain () {
  if ( _Global_ == 'web' ) {
    // H5
    location.href='http://carnt.carnettong.com:8088/CARNT/jsp/pay/indexM.html#/maintainHome';
  } else {
    // App
    sendAppRedirect('maintain');
  }
}
// 打开违章办理
function openIllegal () {
  if ( _Global_ == 'web' ) {
    // H5
    location.href='http://carnt.carnettong.com:8088/CARNT/jsp/pay/indexM.html#/illegalHome';
  } else {
    // App
    sendAppRedirect('illegal');
  }
}
// 打开喷漆
function openSpray () {
  if ( _Global_ == 'web' ) {
    // H5
    location.href='http://carnt.carnettong.com:8088/CARNT//jsp/new_spray/index.html#/';
  } else {
    // App
    sendAppRedirect('spray');
  }
}
// 打开保养年卡
function openMtcard () {
  if ( _Global_ == 'web' ) {
    // H5
    location.href='http://carnt.carnettong.com:8088/CARNT/jsp/pay/indexM.html#/yearCard';
    //location.href='http://4scafe.carnettong.com/CARNT/jsp/pay/indexM.html#/yearCard';
  } else {
    // App
    sendAppRedirect('mtcard');
  }
}
/*
 *  打开4S咖啡
 *  WEB -> 下载App页面
 *  APP -> 4s咖啡
 */
function openFourSCafe() {
  if ( _Global_ == 'web' ) {
    // H5 跳转下载app
    location.href='http://carnt.carnettong.com:8088/4SCAFE/HTML5/aTestWx/dist/index.html';
    //location.href='http://4scafe.carnettong.com/4SCAFE/HTML5/aTestWx/dist/index.html';
  } else {
    // App
    fourSCafe();
  }
}
// 
/*
 *  车品（通用优惠券跳转）
 *  WEB -> 车品
 *  APP -> 车品 carShop
 */
function openCarShop() {
  if ( _Global_ == 'web' ) {
    // H5
    location.href='http://carnt.carnettong.com:8088/CARNT/jsp/pay/indexM.html#/carProduct';
  } else {
    // App
    carShop();
  }
}
// 跳转到订单列表
  function orderList(status){
    var json = "json:" + JSON.stringify({
      action:"orderList",
      type:status
    });
    appLocation(json);
  }
function orderLists(num) {
  if ( _Global_ == 'web' ) {
    // H5
    location.href='http://carnt.carnettong.com:8088/CARNT/jsp/pay/indexM.html#/order/'+num;
  } else {
    // App
    orderList(num);
  }
}

// 跳转到首页
  function openHomeApp(status){
    var json = "json:" + JSON.stringify({
      action:"home"
    });
    alert(json);
    appLocation(json);
  }
function openHome() {
  if ( _Global_ == 'web' ) {
    // H5
    location.href='http://carnt.carnettong.com:8088/CARNT/jsp/pay/indexM.html';
  } else {
    // App
    openHomeApp();
  }
}

// 活动跳转
function action(id){
  var json = "json:" + JSON.stringify({
    action:"act",
    id:'I_'+id
  });
  appLocation(json);
}
function getAppid(){
  var u = navigator.userAgent;
  var isAndroids = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; // android终端
  var isiOSs = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); // ios终端
  var appid='';
  if(isAndroids){
    appid='wxf71262a112685c25';
  }else if(isiOSs){
    appid='wx054c6f61cacfa911';
  }
  return appid;
}
